/* 
 * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
 * Copyright (c) 2006 Christian Walter <wolti@sil.at>
 * All rights reserved.
 *
 */

#ifndef _MB_APP_H
#define _MB_APP_H

#include "mbcom.h"
#include "mbmaster.h"
#include "mbslave.h"
#include "mbdatacb.h"
#include "mbinputdatacfg.h"
#include "dgus_dev.h"
#include "dgusii_dev.h"
#include "vgus_dev.h"

#include "qcom.h"

#ifdef _MAPP_MODULE_
#define MAPP_EXT
#else
#define MAPP_EXT extern
#endif

#define MBAPP_EVENT_MSK 0xFFFFUL

typedef struct
{
	mb_obj_type obj01;
	mb_cmd_buff_type CmdBuff01[32];
	mb_obj_type obj03;
	mb_cmd_buff_type CmdBuff03[32];
	mb_obj_type obj04;
	mb_cmd_buff_type CmdBuff04[32];
	
	qc_obj_type qc01;
	qc_cmd_type qc_cmd01[10];
	qc_obj_type qc03;
	qc_cmd_type qc_cmd03[10];
	qc_obj_type qc04;
	qc_cmd_type qc_cmd04[10];
} mb_type;

MAPP_EXT mb_type mb;

void mb_os_delay(uint32_t ms);
void mb_os_send(uint16_t event);

void mb00_Init(mb_mode_type mbMode, uint32_t ulBaudRate, mb_parity_type eParity);
void mb00_TimeoutHandle(void);

void mb01_Init(mb_mode_type mbMode, uint32_t ulBaudRate, mb_parity_type eParity);
void mb01_TimeoutHandle(void);

void mb02_Init(mb_mode_type mbMode, uint32_t ulBaudRate, mb_parity_type eParity);
void mb02_TimeoutHandle(void);

void mb03_Init(mb_mode_type mbMode, uint32_t ulBaudRate, mb_parity_type eParity);
void mb03_TimeoutHandle(void);

void mb04_Init(mb_mode_type mbMode, uint32_t ulBaudRate, mb_parity_type eParity);
void mb04_TimeoutHandle(void);

void mb05_Init(mb_mode_type mbMode, uint32_t ulBaudRate, mb_parity_type eParity);
void mb05_TimeoutHandle(void);

void mb06_Init(mb_mode_type mbMode, uint32_t ulBaudRate, mb_parity_type eParity);
void mb06_TimeoutHandle(void);

void mb07_Init(mb_mode_type mbMode, uint32_t ulBaudRate, mb_parity_type eParity);
void mb07_TimeoutHandle(void);

void mb08_Init(mb_mode_type mbMode, uint32_t ulBaudRate, mb_parity_type eParity);
void mb08_TimeoutHandle(void);

typedef struct 
{
	uint8_t index;
	uint16_t dict[ 4 ];
} mb_dict_type;


uint16_t qc_reg_get(uint16_t Index);
void qc_reg_set(uint16_t Index, uint16_t Val);
void qc_coil_dat_set(uu16 Bindex, uu8 dat);
	uu8 qc_coil_dat_get(uu16 Bindex);

void qc01_Init(mb_mode_type qcMode, uint32_t ulBaudRate);
void qc02_Init(mb_mode_type qcMode, uint32_t ulBaudRate);
void qc03_Init(mb_mode_type qcMode, uint32_t ulBaudRate);
void qc04_Init(mb_mode_type qcMode, uint32_t ulBaudRate);
void qc05_Init(mb_mode_type qcMode, uint32_t ulBaudRate);
void qc06_Init(mb_mode_type qcMode, uint32_t ulBaudRate);
void qc07_Init(mb_mode_type qcMode, uint32_t ulBaudRate);
void qc08_Init(mb_mode_type qcMode, uint32_t ulBaudRate);

#undef MAPP_EXT

#endif
